package com.java.simple.study.jvm.memstruct.stack;

import java.util.concurrent.TimeUnit;

/**
 * @author zhoujunlin
 * @date 2021/12/11
 * @desc 死锁
 **/
public class Demo1_6 {
    static final A a = new A();
    static final B b = new B();

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            synchronized (a){
                try {
                    TimeUnit.SECONDS.sleep(3);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (b){
                    System.out.println("thread1同时获得到a，b锁");
                }
            }
        }, "thread1").start();

        TimeUnit.SECONDS.sleep(1);

        new Thread(() -> {
            synchronized (b){
                synchronized (a){
                    System.out.println("thread2同时获得到a，b锁");
                }
            }
        }, "thread2").start();

    }


}

class A {
}

class B {
}
